<?php

/* @var $this \yii\web\View */
/* @var $content string */

use app\models\Manager;
use yii\helpers\Html;
use yii\helpers\Url;
use app\assets\AppAsset;

AppAsset::register($this);

$web = Url::base();
$url = \app\librarys\Tools::urlBase();

$menuList = \app\models\Menu::getAllMenus();
$currentControllerId = Yii::$app->controller->id;
$currentActionId = Yii::$app->controller->action->id;

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="<?= $web ?>/css/frame.css" rel="stylesheet">

    <!--pickers css-->
    <link rel="stylesheet" type="text/css" href="<?= $web ?>/css/datepicker-custom.css"/>

    <link rel="stylesheet" type="text/css" href="<?= $web ?>/css/square-blue.css"/>

    <!--    <link rel="stylesheet" type="text/css" href="--><? //= $web ?><!--/css/switchery.css">-->
    <link rel="stylesheet" type="text/css" href="<?= $web ?>/css/bootstrap-switch.css">

    <link rel="stylesheet" type="text/css" href="<?= $web ?>/css/tree-autocomplete.css">
    <link rel="stylesheet" type="text/css" href="<?= $web ?>/css/jquery.Jcrop.css">

    <script src="<?= $web ?>/js/jquery-1.10.2.min.js"></script>
    <script src="<?= $web ?>/js/jquery-ui-1.9.2.custom.min.js"></script>
    <script src="<?= $web ?>/js/jquery-migrate-1.2.1.min.js"></script>
    <script src="<?= $web ?>/js/bootstrap.min.js"></script>
    <script src="<?= $web ?>/js/modernizr.min.js"></script>
    <script src="<?= $web ?>/js/jquery.nicescroll.js"></script>
    <script src="<?= $web ?>/js/typeahead.js"></script>
    <script src="<?= $web ?>/js/underscore.js"></script>
    <script src="<?= $web ?>/js/tree-autocomplete.js"></script>
    <script src="<?= $web ?>/js/bootstrap-datetimepicker.js"></script>
    <script src="<?= $web ?>/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="<?= $web ?>/js/tools.js"></script>
    <script type="text/javascript" src="<?= $web ?>/js/jcrop/jquery.Jcrop.js"></script>

    <!--pickers plugins-->
    <script type="text/javascript" src="<?= $web ?>/js/bootstrap-datepicker.js"></script>

    <!--pickers initialization-->
    <script src="<?= $web ?>/js/pickers-init.js"></script>

    <script type="application/javascript" src="<?= $web ?>/js/jquery.icheck.js"></script>
    <script type="application/javascript" src="<?= $web ?>/js/icheck-init.js"></script>

    <!--    <script type="application/javascript" src="--><? //= $web ?><!--/js/switchery.js"></script>-->

    <script type="application/javascript">
        $(function () {
            $('.switch').find('input[type=checkbox]').bootstrapSwitch();
        });
    </script>

    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
</head>
<body class="sticky-header">
<section>
    <!-- left side start-->
    <div class="left-side sticky-left-side">

        <div class="logo">
            <a><img src="<?= $web ?>/images/logo.png" alt=""></a>
        </div>

        <div class="left-side-inner">
            <!--sidebar nav start-->
            <ul class="nav nav-pills nav-stacked custom-nav">
                <?php
                foreach ($menuList as $menu) {
                    $menuHtml = '';
                    $isMenuActive = false;
                    $pageHref = 'javascript:;';

                    if (isset($menu['controller']) && isset($menu['action'])) {
                        $pageHref = $url . '/' . $menu['controller'] . '/' . $menu['action'];
                        if (($menu['controller'] == $currentControllerId) && ($menu['action'] == $currentActionId)) {
                            $isMenuActive = true;
                            $pageHref = 'javascript:;';
                        }
                    }

                    if (isset($menu['sub_menu_list'])) {
                        $hasSubMenuActive = false;
                        $pageHref = 'javascript:;';
                        foreach ($menu['sub_menu_list'] as $subMenu) {
                            if (isset($subMenu['controller']) && isset($subMenu['action'])) {
                                $pageHref = $url . '/' . $subMenu['controller'] . '/' . $subMenu['action'];
                            }
                            if (($subMenu['controller'] == $currentControllerId) && ($subMenu['action'] == $currentActionId)) {
                                $menuHtml = $menuHtml . '
                                        <li class="active"><a href="' . $pageHref . '">' . $subMenu['name'] . '</a></li>';
                                $hasSubMenuActive = true;
                                $pageHref = 'javascript:;';
                            } else {
                                $menuHtml = $menuHtml . '
                                        <li><a href="' . $pageHref . '">' . $subMenu['name'] . '</a></li>';
                            }
                        }
                        $menuHtml = '<ul class="sub-menu-list">' . $menuHtml . '
                                    </ul>';
                        if ($hasSubMenuActive == true) {
                            $menuHtml = '
                                <li class="menu-list nav-active"><a href="#"><i class="fa ' . $menu['icon'] . '"></i><span>' . $menu['name'] . '</span></a>
                                    ' . $menuHtml . '
                                </li>';
                        } else {
                            $menuHtml = '
                                <li class="menu-list"><a href="#"><i class="fa ' . $menu['icon'] . '"></i><span>' . $menu['name'] . '</span></a>
                                    ' . $menuHtml . '
                                </li>';
                        }
                    } else {
                        if ($isMenuActive == true) {
                            $menuHtml = '
                                <li class="nav-active"><a href="' . $pageHref . '"><i class="fa ' . $menu['icon'] . '"></i><span>' . $menu['name'] . '</span></a></li>';
                        } else {
                            $menuHtml = '
                                <li><a href="' . $pageHref . '"><i class="fa ' . $menu['icon'] . '"></i><span>' . $menu['name'] . '</span></a></li>';
                        }
                    }

                    echo $menuHtml;
                }
                ?>
            </ul>
            <!--sidebar nav end-->
        </div>

        <div class="left-side-footer">
            <div class="text-center">tel : 400-xxx-xxxx</div>
            <div class="text-center">copyright &copy; xxxx</div>
        </div>
    </div>
    <!-- left side end-->

    <!-- header section start-->
    <div class="header-section">

        <!--toggle button start-->
        <a class="toggle-btn hidden"><i class="fa fa-bars"></i></a>
        <!--toggle button end-->

        <!--notification menu start -->
        <div class="menu-right">
            <ul class="notification-menu">
                <!--                <li>-->
                <!--                    <a href="#" class="btn btn-default dropdown-toggle info-number" data-toggle="dropdown">-->
                <!--                        <i class="fa fa-bell-o"></i>-->
                <!--                        <span class="badge">4</span>-->
                <!--                    </a>-->
                <!--                    <div class="dropdown-menu dropdown-menu-head pull-right">-->
                <!--                        <h5 class="title">Notifications</h5>-->
                <!--                        <ul class="dropdown-list normal-list">-->
                <!--                            <li class="new">-->
                <!--                                <a href="">-->
                <!--                                    <span class="label label-danger"><i class="fa fa-bolt"></i></span>-->
                <!--                                    <span class="name">Server #1 overloaded.  </span>-->
                <!--                                    <em class="small">34 mins</em>-->
                <!--                                </a>-->
                <!--                            </li>-->
                <!--                            <li class="new">-->
                <!--                                <a href="">-->
                <!--                                    <span class="label label-danger"><i class="fa fa-bolt"></i></span>-->
                <!--                                    <span class="name">Server #3 overloaded.  </span>-->
                <!--                                    <em class="small">1 hrs</em>-->
                <!--                                </a>-->
                <!--                            </li>-->
                <!--                            <li class="new">-->
                <!--                                <a href="">-->
                <!--                                    <span class="label label-danger"><i class="fa fa-bolt"></i></span>-->
                <!--                                    <span class="name">Server #5 overloaded.  </span>-->
                <!--                                    <em class="small">4 hrs</em>-->
                <!--                                </a>-->
                <!--                            </li>-->
                <!--                            <li class="new">-->
                <!--                                <a href="">-->
                <!--                                    <span class="label label-danger"><i class="fa fa-bolt"></i></span>-->
                <!--                                    <span class="name">Server #31 overloaded.  </span>-->
                <!--                                    <em class="small">4 hrs</em>-->
                <!--                                </a>-->
                <!--                            </li>-->
                <!--                            <li class="new"><a href="">See All Notifications</a></li>-->
                <!--                        </ul>-->
                <!--                    </div>-->
                <!--                </li>-->
                <li>
                    <?php
                    //                    if (Manager::getCurrentManager()['institution_code'] == '0') {
                    ?>
                    <span style="margin-right: 10px">系统机构</span>
                    <?php
                    //                    } else {
                    ?>
                    <span style="margin-right: 10px"></span>
                    <?php
                    //                    }
                    ?>

                    <a href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        <span class="user-name text-center"><?= \app\models\Manager::getCurrentManager()['name'] ?></span>
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-usermenu pull-right">
                        <li><a data-toggle="modal" href="#personDetailModal"><i class="fa fa-user"></i> 修改个人信息</a></li>
                        <li><a data-toggle="modal" href="#modifyPassword"><i class="fa fa-cog"></i> 修改密码</a></li>
                        <li><a href="<?= $url . '/site/logout' ?>"><i class="fa fa-sign-out"></i> 退出</a></li>
                    </ul>
                </li>

            </ul>
        </div>
        <!--notification menu end -->

    </div>
    <!-- header section end-->

    <!-- main content start-->
    <div class="main-content">
        <!--body wrapper start-->
        <div class="wrapper">
            <!--            <div class="row">-->
            <!--                <div class="col-md-12">-->
            <!--                    <!--breadcrumbs start -->
            <!--                    <ul class="breadcrumb panel">-->
            <!--                        <li><a href="#"><i class="fa fa-home"></i> Home</a></li>-->
            <!--                        <li><a href="#">Dashboard</a></li>-->
            <!--                        <li class="active">Current page</li>-->
            <!--                    </ul>-->
            <!--                    <!--breadcrumbs end -->
            <!--                </div>-->
            <!--            </div>-->

            <?= $content ?>
        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer class="sticky-footer">
            <span>tel: 400-xxx-xxxx</span>
            <span>2016 &copy; xxxx</span>
        </footer>
        <!--footer section end-->
    </div>
    <!-- main content end-->
</section>

<div id="loading-frame">
    <div id="loading-mask"></div>
    <div id="loading">
        <div id="loading-center">
            <div id="loading-center-absolute">
                <div class="object" id="object_four"></div>
                <div class="object" id="object_three"></div>
                <div class="object" id="object_two"></div>
                <div class="object" id="object_one"></div>
            </div>
        </div>
    </div>
</div>

<!-- 修改密码-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="modifyPassword" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">修改密码</h4>
            </div>
            <div class="modal-body">
                <div class="form-horizontal adminex-form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">原始密码</label>
                        <div class="col-sm-9">
                            <input type="password" class="form-control" id="oldPassword">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">新密码</label>
                        <div class="col-sm-9">
                            <input type="password" class="form-control" id="newPassword">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">确认新密码</label>
                        <div class="col-sm-9">
                            <input type="password" class="form-control" id="confirmPassword">
                            <label id='alertPassword' style="display: none;">
                                <span style="color: red">与新密码输入不一致，请修改。</span>
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" id="modifyPasswordConfirm">保存</button>
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 修改个人信息-->
<div aria-hidden="true" role="dialog" tabindex="-1" id="personDetailModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">个人信息</h4>
            </div>
            <div class="modal-body" id="person_detail">正在加载数据....</div>
            <div id="new">

            </div>
        </div>
    </div>
</div>

<!-- error information dialog -->
<div aria-hidden="true" role="dialog" tabindex="-1" id="errorModal" class="modal fade">
    <div class="modal-dialog modal-lg modal-dialog-danger">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">错误</h4>
            </div>
            <div class="modal-body" id="errorContainer"></div>
        </div>
    </div>
</div>

</body>

<!--<script type="application/javascript" src="--><? //= $web ?><!--/js/ios-init.js"></script>-->

<script type="application/javascript" src="<?= $web ?>/js/bootstrap-switch.js"></script>

<script src="<?= $web ?>/js/frame.js"></script>
<script>
    (function () {
        $('#personDetailModal').on('show.bs.modal', function (e) {
            $("#person_detail").html('正在加载数据....');
            requestHtml('<?= $url ?>/system/person-info-partview', null, true, function (responseHtml) {
                $("#person_detail").html(responseHtml);
            });
        });

        $('#modifyPassword').on('show.bs.modal', function (e) {
            $("#oldPassword").val("");
            $("#newPassword").val("");
            $("#confirmPassword").val("");
            $("#alertPassword").css("display", "none");
        });

        $('#modifyPasswordConfirm').click(function () {
            var data = {};
            data.oldPassword = $("#oldPassword").val();
            data.newPassword = $("#newPassword").val();
            if (data.newPassword == $("#confirmPassword").val()) {
                requestJson('<?= $url ?>/system/modify-password-handler', data, true, function (responseData) {
                    if (responseData.status == 0) {
                        window.location.reload();
                    } else if (responseData.status == 1) {
                        alert('原始密码不正确！');
                    } else {
                        alert(responseData.message);
                    }
                });
            } else {
                $("#alertPassword").css("display", "block");
            }

        });
    })(jQuery);
</script>
</html>
